from ..controller import KeyframeController
from basemacro import BaseMacro

class LampsOff(BaseMacro):
    def init_macro(self, **kwargs):
        self.duration = 30.
    def _prepare_run(self):
        for device in self.MainController.DeviceSystem.PatchedDevices.itervalues():
            pgroup = device.ParameterGroups.get('Control')
            if not pgroup:
                continue
            paramobj = pgroup.parameter_obj.get('Lamp Off')
            if not paramobj:
                continue
            c = KeyframeController(Property=(paramobj, 'value'))
            c.add_keyframes({0.:0, 1.:0})
            self.add_controller(c)
            c = KeyframeController(Property=(paramobj, 'active'))
            c.add_keyframes({0.:True, 1.:True})
            self.add_controller(c)
    def _check_run(self):
        return not self.MainController.EffectsSystem.Macros['LampsOn'].running
    
MACRO = LampsOff
